package com.example.demo.controller;


import com.example.demo.entity.inventory;
import com.example.demo.service.inventoryserviceInter;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/inventory")
public class inventorycontroller {

    @Autowired
    inventoryserviceInter inventorydao;

    @RequestMapping("/display")
    public PageInfo<inventory> display(@RequestParam(value = "pagenum", required = false, defaultValue = "1")Integer pagenum,
                                       @RequestParam(value = "pagesize", required = false, defaultValue = "5")Integer pagesize,
                                       Model model) {

        PageInfo<inventory> invpageinfo = inventorydao.display(pagenum, pagesize);
        model.addAttribute("invpageinfo", invpageinfo);

        return invpageinfo;
    }

    @RequestMapping("/search")
    public List<inventory> search(inventory i) {
        return inventorydao.search(i);
    }

    @RequestMapping("/delete")
    public int delete(inventory i) {
        return inventorydao.delete(i);
    }

    @RequestMapping("/update")
    public int update(inventory i) {
        return inventorydao.update(i);
    }
}
